package com.itheima.appserver.controller;

import com.itheima.appserver.service.VideoService;
import com.itheima.commons.pojo.Video;
import com.itheima.commons.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 视频操作
 * @Author: lqTao
 * @Date: 2021/12/10 23:46
 */
@RestController
@RequestMapping("/smallVideos")
public class VideoController {

    @Autowired
    VideoService videoService;

    @GetMapping
    public ResponseEntity getVideo(@RequestParam("page") Integer page, @RequestParam("pagesize") Integer pagesize) {
        PageResult video = videoService.getVideo(page, pagesize);
        return ResponseEntity.ok(video);
    }

    //videoThumbnail 视频封面文件
    //videoFile 视频文件
    @PostMapping
    public ResponseEntity saveVideo(@RequestParam MultipartFile videoThumbnail, MultipartFile videoFile) {
        videoService.saveVideo(videoThumbnail, videoFile);
        return ResponseEntity.ok(null);
    }

    //视频点赞
    @PostMapping("/{id}/like")
    public ResponseEntity likeVideo(@PathVariable("id") String videoId) {
        videoService.likeVideo(videoId, Video.class);
        return ResponseEntity.ok(null);
    }

    //视频点赞取消
    @PostMapping("/{id}/dislike")
    public ResponseEntity dislikeVideo(@PathVariable("id") String videoId) {
        videoService.dislikeVideo(videoId, Video.class);
        return ResponseEntity.ok(null);
    }

    //对视频评论
    @PostMapping("/{id}/comments")
    public ResponseEntity commentVideo(@PathVariable("id") String videoId, @RequestBody String comment) {
        videoService.commentVideo(videoId, comment);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论列表
     */
    @GetMapping("/{id}/comments")
    public ResponseEntity queryCommentsList(@PathVariable("id") String videoId,
                                            @RequestParam(value = "page", defaultValue = "1") Integer page,
                                            @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize) {
        PageResult pageResult = videoService.queryCommentList(videoId, page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    //视频评论点赞
    @PostMapping("/comments/{id}/like")
    public ResponseEntity likeCommentVideo(@PathVariable("id") String videoCommentId) {
        videoService.likeCommentVideo(videoCommentId, Video.class);
        return ResponseEntity.ok(null);
    }

    //视频评论点赞取消
    @PostMapping("/comments/{id}/dislike")
    public ResponseEntity dislikeCommentVideo(@PathVariable("id") String videoCommentId) {
        videoService.dislikeCommentVideo(videoCommentId, Video.class);
        return ResponseEntity.ok(null);
    }

    //视频用户关注
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity userFocus(@PathVariable Long uid) {
        videoService.userFocus(uid);
        return ResponseEntity.ok(null);
    }

    //视频用户关注-取消
    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity userFocusUn(@PathVariable Long uid) {
        videoService.userFocusUn(uid);
        return ResponseEntity.ok(null);
    }

}
